package com.the4man.framework.pagemodel;

import com.the4man.framework.utils.RequestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lenovo on 2017/12/12.
 */
public class PageContext extends PPage {
    private static final Logger logger = LoggerFactory.getLogger(PageContext.class);
    private static ThreadLocal<PageContext> pageContext = new ThreadLocal();
    Map<String, PPage> session = new HashMap();

    public PageContext() {
    }

    public static PageContext getContext() {
        PageContext ci = (PageContext)pageContext.get();
        if(ci == null) {
            ci = new PageContext();
            pageContext.set(ci);
        }

        return ci;
    }

    public static void removeContext() {
        pageContext.remove();
    }

    public PPage getSession(String key) {
        return (PPage)this.session.get(key);
    }

    public void putSession(String key, PPage value) {
        this.session.put(RequestUtil.getlogserialnumber() + key, value);
    }

    public void removeSession(String key) {
        if(this.session.get(RequestUtil.getlogserialnumber() + key) != null) {
            this.session.remove(RequestUtil.getlogserialnumber() + key);
        }

    }
}
